﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace QuanLyDiemHocSinh
{
    public partial class Them_Tai_Khoan : System.Web.UI.Page
    {
        String tentk, matkhau, quyen;
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            tentk = tbtentk.Text;
            matkhau = tbmk.Text;
            quyen = ddquyen.Text;
            if (String.Compare(tentk, "") == 0 || String.Compare(matkhau, "") == 0 || String.Compare(quyen, "") == 0)
                lbthongbao.Text = " Nhập đủ dữ liệu vào!";
            else
            {
                string chuoiketnoi = "Server=.\\SqlExpress;Integrated Security=True;Database=QuanLyDiem";
                SqlConnection ketnoi = new SqlConnection(chuoiketnoi);

                SqlCommand cmd = new SqlCommand("insert into NguoiDung (MaNguoiDung,MatKhau,MaQuyen) values (@tentk,@matkhau,@quyen)", ketnoi);
                cmd.Parameters.AddWithValue("@tentk", tentk);
                cmd.Parameters.AddWithValue("@matkhau", matkhau);
                cmd.Parameters.AddWithValue("@quyen", quyen);

                try
                {
                    ketnoi.Open();
                    cmd.ExecuteNonQuery();
                    lbthongbao.Text = "Thêm tài khoản thành công!";
                }
                catch (Exception exx)
                {
                    lbthongbao.Text = exx.ToString();
                }
            }
          
        }
    }
}